package Day02;

public class Demo05 {
    public static void main(String[] args) {
        //二分查找，要求数组有序排序
        int[] a = {10,20,30,40,50,60,70,80,90};
        int m = 40;
        int min = 0;
        int max = a.length-1;
        int middle = (min+max)/2;
        while(true){
            if(m > a[middle]){
                min = middle + 1;
            }else if(m < a[middle]){
                max = middle - 1;
            }else{
                break;
            }
            if(min > max){
                middle = -1;
                break;
            }
            middle = (min+max)/2;
        }
        System.out.println("下标是：" + middle);
    }
}
